package com.study.lu;

import java.util.Arrays;

public class 数组和的中间值坐标 {
    public static void main(String[] args) {
        int[] arrs = new int[]{1, 2, 3, 5, 3, 2, 1};
        System.out.println(printCenter(arrs));
    }

    /**
     * 解体思路：双指针
     * 一个是从左到右求和
     * 一个是从右到左求和
     * @param numbers
     * @return
     */
    private static int printCenter(int[] numbers) {
        int partSum = 0;
        int sum = Arrays.stream(numbers).sum();
        for (int i = 0; i < numbers.length; i++) {
            partSum += numbers[i];
            if (partSum == sum) {
                return i;
            }
            sum = sum - numbers[i];
        }

        return -1;

    }


}
